package com.dz.finance.biz.service.impl;

import com.dz.finance.biz.constant.MsgConstant;
import com.dz.finance.biz.entity.MemberBindWxOpenId;
import com.dz.finance.biz.mapper.MemberBindWxOpenIdMapper;
import com.dz.finance.biz.service.MemberBindWxOpenIdService;
import com.dz.finance.common.exception.BizException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author: DengHaoQi
 * @date: 2024/6/9 17:56
 * @description:
 */

@Slf4j
@Service
@RequiredArgsConstructor
public class MemberBindWxOpenIdServiceImpl implements MemberBindWxOpenIdService {

    private final MemberBindWxOpenIdMapper mapper;

    @Override
    public MemberBindWxOpenId getWxBindOpenId(MemberBindWxOpenId condition) {
        return mapper.selectMemberBindWxOpenId(condition);
    }


    /*
    * 注册
    * */
    @Override
    public void reg(String appId, String openId, Long memberId) {
        MemberBindWxOpenId memberBindWxOpenId = MemberBindWxOpenId.builder()
                .appId(appId)
                .openId(openId)
                .memberId(memberId)
                .disable(0)
                .createTime(new Date())
                .updateTime(new Date())
                .build();
        int row = mapper.insert(memberBindWxOpenId);
        if (row == 0) {
            throw new BizException(MsgConstant.MEMBER_BIND_WECHAT_FAIL);
        }
    }
}
